﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StockDse.Models;

namespace StockDse.Tests.Fakes {

    public class FakeDseRepository : IDseRepository {

        private List<Dse> DseList;

        public FakeDseRepository(List<Dse> Dses) {
            DseList = Dses;
        }

        public IQueryable<Dse> FindAllDses() {
            return DseList.AsQueryable();
        }

        public IQueryable<Dse> FindUpcomingDses() {
            return (from Dse in DseList
                    where Dse.EventDate > DateTime.Now
                    select Dse).AsQueryable();
        }

        public IQueryable<Dse> FindByLocation(float lat, float lon) {
            return (from Dse in DseList
                    where Dse.Latitude == lat && Dse.Longitude == lon
                    select Dse).AsQueryable();
        }

        public Dse GetDse(int id) {
            return DseList.SingleOrDefault(d => d.DseID == id);
        }

        public void Add(Dse Dse) {
            DseList.Add(Dse);
        }

        public void Delete(Dse Dse) {
            DseList.Remove(Dse);
        }

        public void Save() {
            foreach (Dse Dse in DseList) {
                if (!Dse.IsValid)
                    throw new ApplicationException("Rule violations");
            }
        }
    }
}
